package com.persondemo.videoappliction.ui.vip.presenter;

import com.persondemo.videoappliction.bean.PersonSettingBean;
import com.persondemo.videoappliction.bean.UpimgBean;
import com.persondemo.videoappliction.net.BaseApi;
import com.persondemo.videoappliction.net.BaseObserver;
import com.persondemo.videoappliction.net.RxSchedulers;
import com.persondemo.videoappliction.ui.base.BaseContract;
import com.persondemo.videoappliction.ui.base.BasePresenter;
import com.persondemo.videoappliction.ui.vip.contract.SettingContract;

import java.io.File;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;

import okhttp3.MultipartBody;
import okhttp3.RequestBody;

/**
 * Created by Administrator on 2018/4/25.
 */

public class SettingPresenter extends BasePresenter<SettingContract.View> implements SettingContract.Presenter {
    private BaseApi baseApi;

    @Inject
    public SettingPresenter(BaseApi baseApi) {
        this.baseApi = baseApi;
    }

    @Override
    public void upimgdata(MultipartBody.Part file) {
        baseApi.upimgdata(file)
                .compose(RxSchedulers.applySchedulers())
                .compose(mView.bindToLife())
                .subscribe(new BaseObserver<UpimgBean>() {
                    @Override
                    public void onSuccess(UpimgBean upimgBean) {
                        mView.imgdata(upimgBean);
                    }

                    @Override
                    public void onFail(Throwable e) {
                        mView.showFaild();
                    }
                });
    }

    @Override
    public void upperson(String imgs, String username, int sex, String device, String email, String password) {
        baseApi.personsetting(imgs, username, sex, device, email, password)
                .compose(RxSchedulers.applySchedulers())
                .compose(mView.bindToLife())
                .subscribe(new BaseObserver<PersonSettingBean>() {
                    @Override
                    public void onSuccess(PersonSettingBean personSettingBean) {
                        mView.persondata(personSettingBean);
                    }

                    @Override
                    public void onFail(Throwable e) {
                        mView.showFaild();
                    }
                });
    }
}
